package demo;

import java.util.*;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;
import java.util.StringJoiner;

/**
 * @author 胡宇轩
 * @Email: yuxuan.hu01@bianlifeng.com
 */
public class Test {

    public static void main(String[] args) {
        StringJoiner joiner = new StringJoiner(",");
        joiner.add("1");
        joiner.add("3");
        joiner.add("5");
        System.out.println(joiner.toString());
    }
    static void fun() throws InterruptedException {
        Thread.sleep(1000);
    }
    class Solution {
        public String longestCommonPrefix(String[] strs) {
            String commonStr = strs[0];
            for (String s : strs){
                commonStr = getLongestCommonPrefixStr(s, commonStr);
                if(commonStr.equals("")){
                    return "";
                }
            }
            return commonStr;
        }

        String getLongestCommonPrefixStr(String s1, String s2){
            int i = 0;
            int len = Math.min(s1.length(), s2.length());
            while(i < len && s1.charAt(i) == s2.charAt(i)){
                i++;
            }
            return s1.substring(0,i);
        }
    }
}



class quJianJiaoJi {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String[] str = in.nextLine().split("\\n");
        int[] arr = new int[str.length];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = Integer.parseInt(str[i]);
        }
        // 先计算交集
        List<int[]> res = new ArrayList<>();
        for (int i = 0; i < arr.length; i += 2) {
            for (int j = i + 2; j < arr.length; j += 2) {
                int left = Math.max(arr[i], arr[j]);
                int right = Math.min(arr[i + 1], arr[j + 1]);
                if (left <= right) {
                    res.add(new int[]{left, right});
                }
            }
        }
        // 计算完交集，按从小到大排序，左边界升序，相同，有边界升序
        int[][] ans = res.toArray(new int[res.size()][]);
        Arrays.sort(ans, (a, b) -> (a[0] == b[0] ? a[1] - b[1] : a[0] - b[0]));
        // 求交集的并集
        int[][] result = new int[ans.length][2];
        int index = -1;
        for (int[] an : ans) {
            if (index == -1 || an[0] > result[index][1]) {
                result[++index] = an;
            } else {
                result[index][1] = Math.max(result[index][1], an[1]);
            }
        }
        int[][] last = Arrays.copyOf(result, index + 1);
        for (int i = 0; i < last.length; i++) {
            System.out.print(last[i][0]);
            System.out.print(" ");
            System.out.print(last[i][1]);
            if (i != last.length - 1) {
                System.out.print(" ");
            }
        }
    }
}

